<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - libjpeg_test.cpp</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2019  Davis E. King (davis@dlib.net), Nils Labugt
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>setjmp.h<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>stdio.h<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>stdlib.h<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>jpeglib.h<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>iostream<font color='#5555FF'>&gt;</font>

<font color='#0000FF'>struct</font> <b><a name='jpeg_loader_error_mgr'></a>jpeg_loader_error_mgr</b> 
<b>{</b>
    jpeg_error_mgr pub;    
    jmp_buf setjmp_buffer;  
<b>}</b>;

<font color='#0000FF'><u>void</u></font> <b><a name='jpeg_loader_error_exit'></a>jpeg_loader_error_exit</b> <font face='Lucida Console'>(</font>j_common_ptr cinfo<font face='Lucida Console'>)</font>
<b>{</b>
    jpeg_loader_error_mgr<font color='#5555FF'>*</font> myerr <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>jpeg_loader_error_mgr<font color='#5555FF'>*</font><font face='Lucida Console'>)</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>err;

    <font color='#BB00BB'>longjmp</font><font face='Lucida Console'>(</font>myerr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>setjmp_buffer, <font color='#979000'>1</font><font face='Lucida Console'>)</font>;
<b>}</b>

<font color='#009900'>// This code doesn't really make a lot of sense.  It's just calling all the libjpeg functions to make
</font><font color='#009900'>// sure they can be compiled and linked.  
</font><font color='#0000FF'><u>int</u></font> <b><a name='main'></a>main</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
<b>{</b>
    std::cerr <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>This program is just for build system testing.  Don't actually run it.</font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> std::endl;
    <font color='#BB00BB'>abort</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

    FILE <font color='#5555FF'>*</font>fp <font color='#5555FF'>=</font> <font color='#BB00BB'>fopen</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>whatever.jpg</font>", "<font color='#CC0000'>rb</font>" <font face='Lucida Console'>)</font>;

    jpeg_decompress_struct cinfo;
    jpeg_loader_error_mgr jerr;

    cinfo.err <font color='#5555FF'>=</font> <font color='#BB00BB'>jpeg_std_error</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>jerr.pub<font face='Lucida Console'>)</font>;

    jerr.pub.error_exit <font color='#5555FF'>=</font> jpeg_loader_error_exit;

    <font color='#BB00BB'>setjmp</font><font face='Lucida Console'>(</font>jerr.setjmp_buffer<font face='Lucida Console'>)</font>;

    <font color='#BB00BB'>jpeg_create_decompress</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>cinfo<font face='Lucida Console'>)</font>;

    <font color='#BB00BB'>jpeg_stdio_src</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>cinfo, fp<font face='Lucida Console'>)</font>;
    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font> <b>{</b>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>char</u></font> imgbuffer[<font color='#979000'>1234</font>];
        <font color='#BB00BB'>jpeg_mem_src</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>cinfo, imgbuffer, <font color='#0000FF'>sizeof</font><font face='Lucida Console'>(</font>imgbuffer<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#BB00BB'>jpeg_read_header</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>cinfo, TRUE<font face='Lucida Console'>)</font>;

    <font color='#BB00BB'>jpeg_start_decompress</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>cinfo<font face='Lucida Console'>)</font>;

    <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height_ <font color='#5555FF'>=</font> cinfo.output_height;
    <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width_ <font color='#5555FF'>=</font> cinfo.output_width;
    <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> output_components_ <font color='#5555FF'>=</font> cinfo.output_components;

    <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>*</font> rows[<font color='#979000'>123</font>];

    <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>cinfo.output_scanline <font color='#5555FF'>&lt;</font> cinfo.output_height<font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>jpeg_read_scanlines</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>cinfo, <font color='#5555FF'>&amp;</font>rows[cinfo.output_scanline], <font color='#979000'>100</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#BB00BB'>jpeg_finish_decompress</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>cinfo<font face='Lucida Console'>)</font>;
    <font color='#BB00BB'>jpeg_destroy_decompress</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>cinfo<font face='Lucida Console'>)</font>;

    <font color='#BB00BB'>fclose</font><font face='Lucida Console'>(</font> fp <font face='Lucida Console'>)</font>;
<b>}</b>

</pre></body></html>